package com.simple.util.security;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @program: simple_tools
 * @description: 校验手机号码与网址
 * @author: Mr.chen
 * @create: 2020-05-18 11:48
 **/
public class RegExpUtil {
    // 手机校验
    private static final Pattern MOBILE_PATTERN = Pattern.compile("^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$");


    // 网址
    private static final Pattern INTERNET_ADDRESS = Pattern.compile("((http|https):\\/\\/){1}[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])?");

    /**
     * 验证手机号码
     *
     * @param mobileNo
     * @return
     */
    public static boolean isMobile(String mobileNo) {
        if (StringUtils.isBlank(mobileNo)) {
            return false;
        }

        Matcher matcher = MOBILE_PATTERN.matcher(mobileNo);
        return matcher.matches();
    }

    /**
     * 校验网址
     *
     * @param internetAddress
     * @return
     */
    public static boolean isInternetAddress(String internetAddress) {
        if (StringUtils.isEmpty(internetAddress)) {
            return false;
        }

        Matcher matcher = INTERNET_ADDRESS.matcher(internetAddress);
        return matcher.matches();
    }

}
